package git.soulbgm.job;

import git.soulbgm.config.StatisticsConfig;
import git.soulbgm.cache.enumeration.TimeLevel;
import git.soulbgm.pojo.StatisticsInfo;
import org.apache.shardingsphere.elasticjob.api.ShardingContext;
import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob;
import org.springframework.stereotype.Service;

import static git.soulbgm.common.Constants.*;

/**
 * 接收统计作业
 *
 * @author SoulBGM
 * @date 2024-09-22
 */
@Service
public class ProcessingInfoStatisticsJob implements SimpleJob {

    private final StatisticsConfig config;
    private final StatisticsCommonJob statisticsCommonJob;

    public ProcessingInfoStatisticsJob(StatisticsConfig config, StatisticsCommonJob statisticsCommonJob) {
        this.config = config;
        this.statisticsCommonJob = statisticsCommonJob;
    }

    @Override
    public void execute(ShardingContext shardingContext) {
        String groupName = GN_PROCESSING_INFO;
        StatisticsInfo info = config.getInfos().get(groupName);
        TimeLevel timeLevel = info.getTimeLevels().get(0);
        long[] startTimeAndEndTime = getStartTimeAndEndTime(timeLevel);
        statisticsCommonJob.group(groupName, info, startTimeAndEndTime);
    }

}
